#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;

int Combination(int n, int m)
{
	int nume = 1;
	int deno = 1;
	for (int i = 1; i <= n; i++)
	{
		nume *= (m - n + i);
		deno *= i;
	}
	return nume / deno;
}

int Order(char* str, int rid_count,int len)
{
	if (len < 1)
		return 0;
	char head = str[0];
	int sum = 0;
	for (int i = 0; i < head - 'a' - rid_count; i++)
	{
		sum += Combination(len - 1, 26 - i - rid_count - 1);
	}
	if (len>1)
	{
		sum += Order(str + 1, head - 'a' + 1, len - 1);
	}
	return sum;
}
int main()
{
	char str[7];
	FILE* pf_in = fopen("input.txt", "r");
	FILE* pf_out = fopen("output.txt", "w");
	int count = 0;
	fscanf(pf_in, "%d", &count);
	for (int j = 0; j < count; j++)
	{
		fscanf(pf_in, "%s", str);
		int len = strlen(str);
		int sum = 0;
		for (int i = 0; i < len - 1; i++)
		{
			sum += Combination(i + 1, 26);
		}
		fprintf(pf_out, "%d\n", sum + Order(str, 0, len) + 1);
	}
	fclose(pf_in);
	fclose(pf_out);
	return 0;
}

